home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / t3_1 / doc.lha / documentation / manual / debug.mss < prev    next >
Text File  |  1987-06-30  |  18KB  |  452 lines

  1. @part[Debug, root "TMAN.MSS"]    @Comment{-*-System:TMAN-*-}
  2. @chap[Debugging]
  3.  
  4. @label[debugging chapter]  @comment{Referred to from user interface chapter.}
  5.  
  6.  
  7. The facilities described in this chapter are highly
  8. implementation-specific, and subject to change without notice.
  9. Facilities described here are intended either for use directly as
  10. commands, or as utilities for user-written debugging subsystems.
  11.  
  12.  
  13. @section[Errors]
  14. @index[Errors]
  15.  
  16. @label[Errors Interface Section]        @Comment{ref: Errors Section}
  17. @label[dealing section]
  18.  
  19. When the implementation detects an error condition, a message is printed and
  20. a read-eval-print loop is entered in the dynamic context in which
  21. the error occurred.  A number of facilities are available at this
  22. point for debugging and for recovering from the error.
  23.  
  24. Errors are usually detected in conditions which are left
  25. undefined by the manual (see sections @ref[undefined semantics section]
  26. and @ref[errors section]).  These conditions include the following:
  27.  
  28. @itemize[
  29.     An unbound variable is referenced.
  30.  
  31.     A procedure is called with too few or too many arguments.
  32.  
  33.     A non-procedure is called.
  34.  
  35.     An object of the wrong type is passed to a system procedure.
  36.  
  37.     A string or vector index is out of range.
  38.  
  39.     A generic operation is invoked on an object with no method
  40.     to handle it.
  41.  
  42.     The external representation of an object being parsed by @tc[READ-OBJECT]
  43.     or a read macro is syntactically incorrect.  (This kind of error
  44.     is called a @i[read error.])
  45.  
  46.     An object being interpreted as an expression by a compiler or a
  47.     macro expander is syntactically incorrect.  (This kind of error is
  48.     called a @i[syntax error.])
  49.  
  50.     A call to @tc[ERROR] or @tc[UNDEFINED-EFFECT] occurs.
  51. ]
  52.  
  53. Once inside the read-eval-print loop, one may examine the current
  54. environment (e.g., examining variables or the stack) using the
  55. read-eval-print loop (section @ref[REPL section]) or the inspector
  56. (section @ref[inspector section]).
  57.  
  58. Typical actions after an error occurs include:
  59. @begin[itemize] 
  60. The user corrects the error by returning a new value
  61. with @tc[RET].
  62.  
  63. The user goes up one command level by typing the end-of-file character
  64. (see page @pageref[end-of-file]).
  65.  
  66. The user throws to top level by calling @tc[(RESET)] (page @pageref[RESET]).
  67. @end[itemize]
  68.  
  69. Example:
  70.   @begin[ProgramExample]
  71. > (CADR 3)
  72.  
  73. ** Error: attempting to take CADR of 3
  74. >> (RET '(A B))
  75. B
  76. > (PLUS 3 4)
  77.  
  78. ** Error: variable PLUS has no value
  79. >> (RET ADD)
  80. 7
  81.   @end[ProgramExample]
  82.  
  83. @dc[Talk about errors from compiled code.]
  84.  
  85. @info[notes="Settable"]
  86. @desc[(RECKLESSNESS) @yl[] LOW, MEDIUM, @r[or] HIGH]
  87. Doing @tc[(SET (RECKLESSNESS) 'HIGH)] will improve performance at
  88. the expense of error-checking.  Specifically, somewhere between 10
  89. and 25 instructions will be elided from most procedure calls, but
  90. wrong-number-of-argument, undefined-procedure, and object-not-applicable
  91. errors will probably cause illegal memory references or odd address
  92. errors instead of more comprehensible error reports.
  93. @EndDesc[RECKLESSNESS]
  94.  
  95.  
  96. @section[Debugging utilities]
  97.  
  98. @info[NOTES="Special form"]
  99. @desc[(TRACE @i[variable]) @yl[] @i[undefined]]
  100. Reassigns @i[variable], whose value should be a procedure,
  101. to be a new procedure which prints information on the
  102. @tc[(DEBUG-OUTPUT)] stream whenever it is called or returns a value.
  103. @EndDesc[TRACE]
  104.  
  105. @info[NOTES="Special form"]
  106. @desc[(UNTRACE @i[variable]) @yl[] @i[undefined]]
  107. If @i[variable] has a traced procedure as its value,
  108. @tc[UNTRACE] restores it to its original value.
  109. Otherwise it prints a warning and does nothing.
  110. @EndDesc[UNTRACE]
  111.  
  112. @info[NOTES="Special form"]
  113. @desc[(PP @i[procedure]) @yl[] @i[undefined]]
  114. Prints the definition of @i[procedure] on the terminal output stream.
  115. If the source code is not available, then it prints the name of a file
  116. where it can be found.
  117. (See also @tc[PRETTY-PRINT], page @pageref[PRETTY-PRINT],
  118. and @tc[WHERE-DEFINED], page @pageref[WHERE-DEFINED].)
  119. @EndDesc[PP]
  120.  
  121. @desc[(BACKTRACE) @yl[] @i[undefined]]
  122. Prints a one-line summary describing each continuation on the stack.
  123. @index[continuations]
  124. See also @tc[DEBUG], page @pageref[DEBUG].
  125. @EndDesc[BACKTRACE]
  126.  
  127.  
  128. @section[The inspector]
  129. @label[inspector section]
  130.  
  131. @tc[CRAWL], also known as the @iix[inspector],
  132. is a stack and structure inspector.
  133. It consists of a command loop and a set of commands.
  134. The inspector keeps track of a @i[current object], and a stack of
  135. objects which have previously been current objects.  Some inspector
  136. commands move from one object to another.
  137.  
  138. The command loop operates as follows: the current object is
  139. @qu"summarized" (that is, printed or displayed somehow); a prompt is
  140. printed; a line is read; and any commands on the line are executed.
  141. One can give one or more commands on a single input line.
  142.  
  143. The current object may be any object.  If it is a continuation (stack frame),
  144. the name of the procedure which contains the continuation's return point
  145. is printed, and the prompt is @qu"@tc[debug:]".  Otherwise, the object
  146. is printed (up to a maximum of one line of output),
  147. and the prompt is @qu"@tc[crawl:]".
  148. @index[stack]
  149. @index[frames]
  150. @index[continuations]
  151.  
  152. The meanings of some commands vary depending on what kind of object
  153. the current object is,  and not all commands are
  154. appropriate for all kinds of objects.
  155.  
  156. @desc[(DEBUG) @yl[] @i[undefined]]
  157. @tc[(DEBUG)] enters the inspector.  The current object becomes a continuation
  158. near the top of the stack (more precisely, the continuation to which
  159. the value passed to @tc[RET] will be given).
  160. @EndDesc[DEBUG]
  161.  
  162. @desc[(CRAWL @i[object]) @yl[] @i[undefined]]
  163. Enters the inspector.  The current object becomes @i[object].
  164. @EndDesc[CRAWL]
  165.  
  166. Inspector commands:
  167.  
  168. @begin[Description]
  169. @tc[?]@\@i[Help:] prints a list of inspector commands, with one-line
  170. summaries.
  171.  
  172. @tc[Q]@\@i[Quit:] exits out of the inspector, usually back to the
  173. read-eval-print loop.
  174.  
  175. @tc[U]@\@i[Up:] pops the stack of saved objects.  The current object is
  176. forgotten, and the inspector moves to the previous current object.
  177.  
  178. @tc[D]@\@i[Down:] if the current object is a continuation,
  179. moves to the next continuation deeper in the stack, that is, to the
  180. continuation that
  181. was pushed prior to the current continuation.
  182.  
  183. @begin[multiple]
  184. @tc[X]@\@i[Exhibit:] prints useful information about the current object.
  185. The exact behavior of this varies depending on the type of the object.
  186. For structures, all of the structure's components are displayed.
  187. For continuations, any saved values are printed.  Integers are printed
  188. in various radices.
  189.  
  190. For some kinds of object, such as structures and vectors, the contents
  191. of an object will be displayed in a menu form, as a sequence of lines of
  192. the form
  193. @w[@qu"@tc<[@i[key]] @i[component]>"].
  194. In this case, giving @i[key] as an inspector command will move to
  195. @i[component], which then becomes the current object.
  196. @end[multiple]
  197.  
  198. @i[integer]@\@i[Select element:] in the case of a list or vector,
  199. this moves to the appropriate component.  For example, if the current object
  200. is a list, then @tc[3] as an inspector command is the same as @tc[A CADDDR]:
  201. it moves to the list's fourth element.
  202.  
  203. @i[selector]@\@i[Select component:] if the current object is a structure,
  204. typing a selector name will move to that component of the structure.
  205.  
  206. @tc[B]@\@i[Breakpoint:] enters a read-eval-print loop.  Executing
  207. @tc[(RET)] will return back into the inspector.  The read-eval-print
  208. loop will execute either in @tc[(REPL-ENV)], or, if the current object
  209. is a continuation or procedure created by interpreted code (i.e. code
  210. compiled by the standard compiler, as opposed to TC), in the lexical
  211. environment of the object.  Inside the breakpoint loop, the system
  212. variable @tc[*OBJ*] is bound to the current object.
  213.  
  214. @tc[C]@\@i[Crawl:] moves to a new object.  The
  215. object is obtained by evaluating an input expression, which is
  216. read either from the command line or in response to a prompt.
  217. The environment of the evaluation is one appropriate to
  218. the current object, as with the @tc[B] command.
  219.  
  220. @tc[E]@\@i[Evaluate:] evaluates an expression.  The expression is read
  221. and evaluated as
  222. with the @tc[C] command.  The result of the evaluation is printed, but
  223. the current object remains the same.
  224.  
  225. @tc[A]@\@i[Apply:] applies a procedure to the current object, and move to the
  226. result of that call.  An expression evaluating to the procedure is
  227. read as with the @tc[C] command.
  228.  
  229. @tc[M]@\@i[Macroexpand:] performs one macro expansion on the current
  230. object, which should be a list, and the current object becomes the result
  231. of the macro expansion.
  232. @index[Macros]
  233.  
  234. @tc[P]@\@i[Pretty-print:] prints the current object using the pretty
  235. printer.
  236. If the current object is a continuation, then this command tries to
  237. print the expression to which the value returned by the continuation
  238. is to be supplied.
  239.  
  240. @tc[R]@\@i[Return:] if the current object is a continuation, returns a
  241. value to it.  The value is obtained as with the @tc[C],
  242. @tc[E], and @tc[A] commands.
  243.  
  244. @comment{   not implemented in 2.7.
  245.     @tc[R]@\@i[Right:] if the current object is a list, this is the same
  246.     as @tc[A CDR]: that is, it moves to the list's cdr.
  247. }
  248.  
  249. @tc[W]@\@i[Where-defined:] prints the result of calling @tc[WHERE-DEFINED]
  250. on the current object.
  251.  
  252. @tc[V]@\@i[Unit:] moves to a template's or procedure's
  253. unit.  Units are not documented, but the @tc[X] command works with them.
  254. This command is intended primarily for the use of the @Timp[] implementors.
  255. @end[Description]
  256.  
  257. The control stack which one inspects by invoking the
  258. inspector with @tc[(DEBUG)] is a sequence of continuations, or stack
  259. frames.  These differ from activation records in implementations of
  260. languages such as C or Lisp in that they represent future computations
  261. rather than past calls.  A full call history is not easily
  262. available in tail-recursive languages such a @Tau[] and Scheme.
  263. This is implementation-dependent, of course, and future @Tau[]
  264. implementations may maintain call histories for debugging purposes.
  265.  
  266. Each continuation represents a control point which will make use of
  267. the value returned to the continuation.  Usually these control points
  268. correspond to the arguments in a call, the predicate in an @tc[IF]
  269. or @tc[COND], or any but the last subform of a block.  For example,
  270. when evaluating a call, a continuation is constructed for each argument
  271. in the call, because these values will be used when the call actually
  272. occurs.  In the example below, the continuations into @tc[FACT] were
  273. mostly delivering values to the second argument position in the call
  274. to @tc[*].
  275.  
  276. The three-column synopsis that the inspector prints for continuations
  277. is the same as that printed by @tc[BACKTRACE] (page
  278. @pageref[BACKTRACE]).  The first column is the name of the procedure
  279. into which control will return, or @tc[(anonymous)] if no procedure
  280. name is available (as for procedures created by anonymous top-level
  281. @tc[LAMBDA]-expressions instead of by @tc[DEFINE]).  The second column
  282. is the name of the source file containing the procedure, and the third
  283. column is relevant source code, if available.
  284.  
  285. Here is a sample interaction with the inspector.
  286. Commentary is in Roman font on the right.
  287. The terms @qu"frame," @qu"stack frame," and @qu"continuation" are
  288. used interchangeably.
  289. @begin[ProgramExample]
  290. > (define (fact n)                      @r[Define factorial function.]
  291.     (cond ((= n 0) i)                   @r[Bug: @tc[i] instead of @tc[1].]
  292.           (else (* n (fact (- n 1))))))
  293. #{Procedure 120 FACT}
  294. > (fact 4)
  295.  
  296. ** Error: variable I is unbound         @r[Error detected by interpreter.]
  297. >> (debug)
  298. #{Continuation 121}                     @r[Current object is this frame.]
  299.  BIND-INTERNAL         THROW            @r[Internal to the implementation.]
  300. debug: d                                @r[Go down one frame.]
  301. #{Dynamic-state-transition 122}         @r[Also internal, keep going.]
  302. debug: d
  303. #{Continuation 123}
  304.  FACT                  ()         I     @r[Okay, this looks good.]
  305. debug: d
  306. #{Continuation 124}
  307.  FACT                  ()         (* N (FACT (- N 1)))
  308. debug: e n                              @r[Evaluate @tc[N] in this frame.]
  309. 1                                       @r[Value is 1.]
  310. debug: d
  311. #{Continuation 125}
  312.  FACT                  ()         (* N (FACT (- N 1)))
  313. debug: e n                              @r[Value is 2 in this frame.]
  314. 2
  315. debug: d d                              @r[Go down two frames.]
  316. #{Continuation 126}
  317.  FACT                  ()         (* N (FACT (- N 1)))
  318. debug: d
  319. #{Continuation 127}
  320.  READ-EVAL-PRINT-LOOP  REPL             @r[@tc[FACT]'s caller (i.e. top level).]
  321. debug: u u u u u                        @r[Up five frames.]
  322. #{Continuation 123}
  323.  FACT                  ()         I
  324. debug: r 1                              @r[Return the value 1 to this frame.]
  325. 24                                      @r[Execution proceeds, and the value]
  326. >                                       @r[24 comes out.]
  327. @end[ProgramExample]
  328.  
  329.  
  330.  
  331. @section[Debugging primitives]
  332.  
  333. This section describes routines which may be useful in writing debugging
  334. aids.  Note that they are not part of the language, and therefore should be
  335. avoided in @qu"ordinary" programs.  Relying on these routines may lead
  336. to programs which behave differently depending on how the programs
  337. are compiled (TC or standard compiler), or which fail to work
  338. across releases.
  339.  
  340. @info[NOTES="Operation"]
  341. @desc[(WHERE-DEFINED @i[object]) @yl[] @i[filename]]
  342. Tries to find a filename for the source file wherein
  343. @i[object] (usually a procedure) is defined.
  344. @EndDesc[WHERE-DEFINED]
  345.  
  346. @info[NOTES="Operation"]
  347. @desc[(IDENTIFICATION @i[object]) @yl[] @i[symbol] @r[or] @i[false]]
  348. If appropriate, this returns a symbol naming a variable which, in some
  349. environment, might be defined to be the @i[object].  If no such
  350. identification is appropriate, @tc[IDENTIFICATION] returns false.  This
  351. behavior is heuristic, not contractual; for no value is @tc[IDENTIFICATION]
  352. required to return non-null.
  353.  
  354.   @begin[ProgramExample]
  355. (IDENTIFICATION CADR)                @ev[]  CADR
  356. (LET ((X CADR)) (IDENTIFICATION X))  @ev[]  CADR
  357.   @end[ProgramExample]
  358. @EndDesc[IDENTIFICATION]
  359.  
  360. @info[NOTES="Operation"]
  361. @desc[(ARGSPECTRUM @i[procedure]) @yl[] @i[pair]]
  362. Returns an @i[argspectrum] for @i[procedure].  An argspectrum is a pair
  363. @wt[(@i[min] . @i[max])] which describes the number of arguments that
  364. @i[procedure] expects to receive when called.  @i[Min] is always an
  365. integer giving the minimum number of arguments expected; @i[max] is
  366. either an integer giving a maximum, or it is @tc[()], meaning that exactly
  367. @i[min] arguments are required, or it is @tc[T], meaning that any number
  368. of arguments (but at least @i[min]) are acceptable.  @dc[This convention
  369. seems pretty random; suggest something better.]
  370. @EndDesc[ARGSPECTRUM]
  371.  
  372. @desc[(DISCLOSE @i[procedure]) @yl[] @i[list] @r[or] @i[false]]
  373. Attempts to reconstruct a source expression from which @i[procedure]
  374. may have been compiled.  This may work for code compiled using the
  375. standard compiler, but is likely to fail to work for code compiled using
  376. TC.  Returns false if no source code can be obtained.
  377. @EndDesc[DISCLOSE]
  378.  
  379. @desc[(GET-ENVIRONMENT @i[procedure]) @yl[] @i[environment] @r[or] @i[false]]
  380. Attempts to reconstruct an environment in which @i[procedure]
  381. may have been loaded (or run).  This may work for code compiled using the
  382. standard compiler, but is likely to fail to work for code compiled using
  383. TC.  Returns false if no environment can be obtained.
  384. @EndDesc[GET-ENVIRONMENT]
  385.  
  386. @desc[(STRUCTURE-TYPE @i[object]) @yl[] @i[stype] @r[or] @i[false]]
  387. If @i[object] is a structure, this returns the structure type of which
  388. it is an instance.  If @i[object] is not a structure, it returns false.
  389. @tc[STRUCTURE-TYPE] is to be used with care since it may violate the
  390. data protection otherwise provided by structure types.  That is, anyone
  391. who is given a structure may find out about its internals.
  392. @EndDesc[STRUCTURE-TYPE]
  393.  
  394. @info[EQUIV="MAPATOMS"]
  395. @desc[(WALK-SYMBOLS @i[procedure]) @yl[] @i[undefined]]
  396. Calls @i[procedure] on every accessible symbol.
  397. @EndDesc[WALK-SYMBOLS]
  398.  
  399.  
  400. @section[Miscellaneous]
  401.  
  402. @desc[*T-VERSION-NUMBER* @yl[] @i[integer]]
  403. An integer which gives the version number of the currently running @Tau[]
  404. implementation.
  405. The integer has the form
  406.   @begin[ProgramExample]
  407. (+ (* @i[major-version-number] 1000) @i[minor-version-number])
  408.   @end[ProgramExample]
  409. For example, in @Timp[] 2.7, @tc[*T-VERSION-NUMBER*] is @tc[2007].  Knowledge
  410. of the version number may be useful in dealing with
  411. incompatibilities between @Timp[] releases, so that programs may
  412. conditionally adjust their state according to the version, and thus
  413. be able to run in both older and newer releases.
  414. @enddesc[*T-VERSION-NUMBER*]
  415.  
  416. @desc[*T-IMPLEMENTATION-ENV* @yl[] @i[locale]]
  417. This environment contains variables internal to the implementation of
  418. @Tau[].
  419.   @begin[ProgramExample]
  420. (IMPORT *T-IMPLEMENTATION-ENV* %%PAIR-TAG)
  421.   @end[ProgramExample]
  422. @enddesc[*T-IMPLEMENTATION-ENV*]
  423.  
  424. @desc[*TC-ENV* @yl[] @i[locale]]
  425. This environment contains variables internal to the implementation
  426. of TC.
  427. @EndDesc[*TC-ENV*]
  428.  
  429. @desc[(GC) @yl[] @i[undefined]]
  430. Invokes the garbage collector.@index[Garbage collection]
  431. Garbage collection is a low-level process by which the memory used by
  432. objects which are no longer accessible is reclaimed for use by new
  433. objects.
  434. Ordinarily, garbage collection is invoked asynchronously as the need
  435. arises, so explicit calls to @tc[GC] are unnecessary.
  436.  
  437. A side-effect of garbage collection is that any streams created by
  438. @tc[OPEN] which are both inaccessible and still open, are closed.
  439.  
  440. See also section @ref[OBJECT-HASH].
  441. @EndDesc[GC]
  442.  
  443. @desc[(GC-STATS) @yl[] @i[undefined]]
  444. Prints some statistics about the most recent garbage collection.
  445. @EndDesc[GC-STATS]
  446.  
  447. @info[NOTES="Settable"]
  448. @desc[(GC-NOISILY?) @yl[] @i[boolean]]
  449. Switch, initially true.  If true, then the garbage collector will print
  450. messages when invoked.  If false, it will do its work silently.
  451. @EndDesc[GC-NOISILY?]
  452.